package com.xja.ssm.controller;

import com.xja.ssm.entity.House;
import com.xja.ssm.entity.Htype;
import com.xja.ssm.service.HouseService;
import com.xja.ssm.service.HtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("house")
public class HouseController {
    @Autowired
    private HouseService houseService;
    @Autowired
    private HtypeService htypeService;

    @RequestMapping("list")
    public String list(Model model){
        try {
            List<House> houseList = houseService.selectAll();
            model.addAttribute("houseList",houseList);
            return "page/list";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "error";
    }
    @RequestMapping("detail")
    public String detail(Integer id,Model model){
        try {
            House house = houseService.selectById(id);
            Htype htype = htypeService.selectById(house.getTypeId());
            model.addAttribute("house",house);
            model.addAttribute("htype",htype);
            return "page/details";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}
